//
//  ChildListCell.m
//  IpadTestB
//
//  Created by edianzu on 2017/6/28.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ChildListCell.h"
@interface ChildListCell()
@property(nonatomic,copy)NSIndexPath*  integerS;
@end
@implementation ChildListCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
    }
//    self.selectionStyle =UITableViewCellSelectionStyleNone;
    return self;
}

-(void)creatUI{
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = [UIFont systemFontOfSize:19*AutoScaleHorizontal];
    self.nameLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(60*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(200*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    self.sexLabel = [[UILabel alloc]init];
    self.sexLabel.font = [UIFont systemFontOfSize:19*AutoScaleHorizontal];
    self.sexLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.sexLabel];
    [self.sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.nameLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    self.ageLabel = [[UILabel alloc]init];
    self.ageLabel.font = [UIFont systemFontOfSize:19*AutoScaleHorizontal];
    self.ageLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.ageLabel];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.sexLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    self.classLabel = [[UILabel alloc]init];
    self.classLabel.font = [UIFont systemFontOfSize:19*AutoScaleHorizontal];
    self.classLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.classLabel];
    [self.classLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.ageLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(200*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    self.responsLabel = [[UILabel alloc]init];
    self.responsLabel.font = [UIFont systemFontOfSize:19*AutoScaleHorizontal];
    self.responsLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.responsLabel];
    [self.responsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.classLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(200*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.editBtn addTarget:self action:@selector(bringEditView) forControlEvents:UIControlEventTouchUpInside];
    [self.editBtn setImage:[UIImage imageNamed:@"editimg"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.editBtn];
    [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.classLabel.mas_right);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(70*AutoScaleHorizontal, 75*AutoScaleVertical));
    }];
    
    
}
//孩子名单CELL
-(void)relayoutUIWithModel:(ChildModel*)model{
    [self.editBtn removeFromSuperview];
    self.nameLabel.text = model.ChildName;
    if (model.ResponsibleTeacher != nil) {
        self.responsLabel.text = model.ResponsibleTeacher;
    }else{
    self.responsLabel.text = @"无负责教师";
    }
    NSString * birthStr = [model.Birthday substringWithRange:NSMakeRange(0, 10)];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *birthDate = [dateFormatter dateFromString:birthStr];
    NSString * realAge = [self dateToDetailOld:birthDate];
    if ([realAge integerValue]<3) {
        self.ageLabel.text = [NSString stringWithFormat:@"3岁"];
    }else{
    self.ageLabel.text = [NSString stringWithFormat:@"%@岁", realAge];
    }
    
    if ([model.Gender isEqual:@1]) {
        self.sexLabel.text = @"男";
    }else{
        self.sexLabel.text = @"女";
    }
    self.classLabel.text = model.Name;
    
}
//营销场景孩子cell
-(void)setUiWithSaleModel:(ChildModel*)model andinteger:(NSIndexPath*)integerPath{
    self.integerS = integerPath;
    [self.responsLabel removeFromSuperview];
    [self.classLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.ageLabel.mas_right).with.offset(200*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    UIView * view = [[UIView alloc]init];
    view.backgroundColor= UIColorFromRGB(241, 244, 248);
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(10*AutoScaleVertical);
    }];
    self.nameLabel.text = model.ChildName;
    NSString * birthStr = [model.Birthday substringWithRange:NSMakeRange(0, 10)];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *birthDate = [dateFormatter dateFromString:birthStr];
    NSString * realAge = [self dateToDetailOld:birthDate];
    
    if ([realAge integerValue]<3) {
        self.ageLabel.text = [NSString stringWithFormat:@"3岁"];
    }else{
        self.ageLabel.text = [NSString stringWithFormat:@"%@岁", realAge];
    }
    if ([model.Gender isEqual:@1]) {
        self.sexLabel.text = @"男";
    }else{
        self.sexLabel.text = @"女";
    }
    self.classLabel.textColor = [UIColor redColor];
    if (model.TestStatus == YES) {
        self.classLabel.text = @"已测完";
        self.classLabel.textColor = UIColorFromRGB(0, 165, 155);
    }else{
    self.classLabel.textColor = [UIColor redColor];
    self.classLabel.text = @"未测完";
    }
}

#pragma mark 按钮方法
-(void)bringEditView{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    self.backView = [[UIView alloc]init];
    self.backView.backgroundColor = [UIColor clearColor];
    self.backView.userInteractionEnabled =YES;
    [window addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(window);
    }];
    [window bringSubviewToFront:self.backView];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(moveOut)];
    [self.backView addGestureRecognizer:tap];
    
    
    self.editImgView =[[ UIImageView alloc]init];
    self.editImgView.userInteractionEnabled = YES;
    self.editImgView.backgroundColor = [UIColor clearColor];
    self.editImgView.image = [UIImage imageNamed:@"smallCircle"];
    [self.backView addSubview:self.editImgView];
    [self.editImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.editBtn.mas_bottom).with.offset(-30*AutoScaleVertical);
        make.left.mas_equalTo(self.editBtn.mas_left).with.offset(-55*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(125*AutoScaleHorizontal, 50*AutoScaleVertical));
    }];
    
    self.editImgBtnDelete = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.editImgBtnDelete addTarget:self action:@selector(shanchu) forControlEvents:UIControlEventTouchUpInside];
    self.editImgBtnDelete.backgroundColor = [UIColor whiteColor];
    [self.editImgBtnDelete setImage:[UIImage imageNamed:@"deleteIMG"] forState:UIControlStateNormal];
    [self.editImgBtnDelete setTitle:@"删除" forState:UIControlStateNormal];
    [self.editImgBtnDelete setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.editImgView addSubview:self.editImgBtnDelete];
    [self.editImgBtnDelete mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.editImgView.mas_top).with.offset(20*AutoScaleVertical);
        make.left.mas_equalTo(self.editImgView.mas_left).with.offset(5*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(115*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
}

-(void)moveOut{
    [self.backView removeFromSuperview];
}

-(void)shanchu{
    NSLog(@"shanchu");
    [self.backView removeFromSuperview];
    self.callDelete(self.integerS);
}

@end















